home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date : April 27 1999.
- //
- //<doc>
- //<name stitchAndExplodeShell>
- //<owner "Alias|Wavefront Unsupported">
- //
- //<synopsis>
- // string[] stitchAndExplodeShell()
- //
- //<description>
- // Given a group of NURBS surfaces which are connected, the script
- // stitches the surfaces together as a shell and subsequently
- // creates trimmed NURBS surface shapes corresponding to the
- // faces comprising the shell using a surfaceVarGroup.
- //<P>
- // The stitchAndExplode is performed by hooking up
- // the selected NURBS surfaces to a stitchAsNurbsShell node,
- // which in turn is connected to a explodeNurbsShell node.
- //<P>
- // This is useful in removing cracks which show up while
- // rendering NURBS surfaces as the tesselation carried out
- // to render the triangles do not have the same vertices
- // across the shared edges.
- //
- //<flags>
- // none.
- //
- //<returns>
- // string[] : The surface var group.
- //
- //<examples>
- // select -r sphere1 fillet1 sphere2 ;
- // string $osrf[] = stitchAndExplodeShell
- // // Result : { varGroup } //
- //
- //</doc>
- //
-
- global proc string[] stitchAndExplodeShell()
- //
- // Description :
- //
- {
-
- string $osrf[] ;
- global int $gSelectNurbsSurfacesBit ;
-
- string $slist[] = `ls -sl` ;
- if( size($slist) == 0 ) {
- error "select a NURBS surface to convert.";
- }
- string $srf[] ;
- $srf = `filterExpand -ex true -sm $gSelectNurbsSurfacesBit $slist` ;
- if( size($srf) == 0 ) {
- error "select at least one NURBS surface.";
- return $osrf ;
- }
-
- // create a stitch node.
- //
- int $i;
- int $ns = size($srf) ;
- string $stitchShell ;
- if( catch( $stitchShell = `createNode stitchAsNurbsShell` ) ) {
- error "Failed in stitchAsNurbsShell node creation !" ;
- return $osrf ;
- }
-
- string $inAttr ;
- string $outAttr;
- for( $i = 0 ; $i < $ns ; $i++ ) {
- $inAttr = $srf[$i] + ".ws[0]" ;
- $outAttr = $stitchShell + ".is[" + $i + "]" ;
- connectAttr $inAttr $outAttr ;
- }
-
- // create an explode node.
- //
- string $explodeShell ;
- if( catch( $explodeShell = `createNode explodeNurbsShell` ) ) {
- error "Failed in explodeNurbsShell node creation !" ;
- delete $stitchShell ;
- return $osrf ;
- }
-
- $inAttr = $stitchShell + ".osh" ;
- $outAttr = $explodeShell + ".ish" ;
- connectAttr $inAttr $outAttr ;
-
- // get the stitched pieces.
- //
- string $varGroup ;
- if( catch( $varGroup = `createNode surfaceVarGroup` ) ) {
- error "Failed in surfaceVarGroup node creation !" ;
- delete $stitchShell ;
- delete $explodeShell ;
- return $osrf ;
- }
-
- // connect explode shell output to
- // the vargroup input.
- //
- $inAttr = $explodeShell + ".os" ;
- $outAttr = $varGroup + ".cr" ;
- connectAttr $inAttr $outAttr ;
-
- // create a nurbs surface and temporarily hook
- // it to varGroup for a compute.
- //
- string $tempSrf = `createNode nurbsSurface` ;
- $inAttr = $varGroup + ".l[0]" ;
- $outAttr = $tempSrf + ".cr" ;
- connectAttr $inAttr $outAttr ;
- $outAttr = $tempSrf + ".degreeU" ;
- getAttr $outAttr ;
-
- // get the # of surfaces in var group.
- //
- $outAttr= $varGroup + ".mc" ;
- int $n = `getAttr $outAttr` ;
-
- // delete the temporary surface.
- //
- delete $tempSrf ;
-
- // select the var group.
- //
- if( $n > 0 ) {
- $osrf[0] = $varGroup;
- select -r $varGroup ;
- string $child[] ;
- $child = `listRelatives $varGroup` ;
- }
-
- // delete history.
- //
- //delete -ch $varGroup ;
-
- // error message on failure.
- //
- if( $n <= 0 ) {
- error "stitchAndExplodeShell script failed on selected NURBS surfaces.";
- }
-
- return $osrf ;
- }
-